import { GET_TAGS, SET_TAGS, TAGS_ACTION, STORAGE_TAGS } from '@/utils/Const';
import { Commit } from 'vuex';
import Storage from '@/utils/Storage';
import { deepCopy } from '@/utils/Tools.js';

interface State {
  value: string
}
export default {
  namespaced: true,
  state: {
    value: {
      editableTabsValue: '首页',
      editableTabs: Storage.get(STORAGE_TAGS, 1) || [{
        title: '首页',
        path: '/dashboard'
      }]
    }
  },
  getters: {
    [GET_TAGS](state: State) {
      return state.value
    }
  },
  mutations: {
    [SET_TAGS](state: State, payload): void {
      state.value = deepCopy(payload)
      Storage.set(STORAGE_TAGS, state.value, 1);
    }
  },
  actions: {
    async [TAGS_ACTION](context: { commit: Commit }, paylod) {
      context.commit(SET_TAGS, paylod);
    }
  }
}